package android.slc.db_objectbox.utils;

import android.slc.db_objectbox.sys.entity.CsDictData;

import com.blankj.utilcode.util.CollectionUtils;
import com.blankj.utilcode.util.StringUtils;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Filter;

import java.util.ArrayList;
import java.util.List;

public class DictUtils {
    public static List<String> dictDataList2LabelList(List<CsDictData> csDictDataList) {
        List<String> labelList = new ArrayList<>();
        CollectionUtils.forAllDo(csDictDataList, new CollectionUtils.Closure<CsDictData>() {
            @Override
            public void execute(int index, CsDictData item) {
                labelList.add(item.getDictLabel());
            }
        });
        return labelList;
    }

    public static String getLabelByValue(List<CsDictData> csDictDataList, String value) {
        CsDictData dictData = CollectionUtil.findOne(csDictDataList, new Filter<CsDictData>() {
            @Override
            public boolean accept(CsDictData csDictData) {
                return StringUtils.equals(csDictData.getDictValue(), value);
            }
        });
        if (dictData != null) {
            return dictData.getDictLabel();
        }
        return null;
    }
}
